package com.wnx.job.modules.nms.controller;


import com.wnx.job.common.api.Const;
import com.wnx.job.common.api.PageResult;
import com.wnx.job.common.api.QueryPageBean;
import com.wnx.job.common.api.ResultData;
import com.wnx.job.common.mapstruct.ArticleAttachmentMapper;
import com.wnx.job.modules.nms.dto.ArticleAttachmentParam;
import com.wnx.job.modules.nms.model.NmsArticleAttachment;
import com.wnx.job.modules.nms.service.NmsArticleAttachmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wangnaixing
 * @since 2021-12-16
 */
@Slf4j
@RestController
@RequestMapping("/nms/nmsArticleAttachment")
@Api(tags = "ArticleAttachmentController",description = "咨询附件管理")
public class NmsArticleAttachmentController {

    @Resource
    private NmsArticleAttachmentService articleAttachmentService;

    /**
     * 添加咨询附件
     * @param articleAttachment
     * @return
     */
    @PostMapping("/save")
    @ApiOperation("添加咨询附件")
    public ResultData<String> save(@RequestBody @Validated ArticleAttachmentParam articleAttachment){
        log.info("===========系统正在进行添加咨询附件=======");
        NmsArticleAttachment tbArticleAttachment = ArticleAttachmentMapper.INSTANCE.toPojo(articleAttachment);
        articleAttachmentService.save(tbArticleAttachment);
        log.info("===========系统正在进行添加咨询附件成功！=======");
        return ResultData.success(Const.ADD_ARTICLE_ATTACHMENT_SUCCESS);
    }

    /**
     * 删除咨询附件
     * @param id
     * @return
     */
    @GetMapping("/delete/{id}")
    @ApiOperation("删除咨询附件")
    public ResultData<String> delete(@PathVariable(name = "id")Long id){
        log.info("======系统正在删除咨询附件，咨询附件ID为{}=========",id);
        articleAttachmentService.removeById(id);
        log.info("系统成功删除咨询附件！！！！");
        return ResultData.success(Const.DELETE_ARTICLE_ATTACHMENT_SUCCESS);
    }

    /**
     * 根据咨询附件ID查看咨询附件详情
     * @param id
     * @return
     */
    @GetMapping("/findById/{id}")
    @ApiOperation("根据咨询附件ID查看咨询附件详情")
    public ResultData<ArticleAttachmentParam> findById(@PathVariable(name = "id")Long id){
        log.info("======系统正在咨询附件详情，咨询附件ID为{}=========",id);
        ArticleAttachmentParam articleAttachment = articleAttachmentService.findById(id);
        log.info("======系统正在咨询附件详情，咨询附件为{}=========",articleAttachment);
        return ResultData.success(Const.QUERY_ARTICLE_ATTACHMENT_SUCCESS,articleAttachment);
    }

    /**
     *分页查询咨询附件
     * @param queryPageBean
     * @return
     */
    @PostMapping("/findByPage")
    @ApiOperation("分页查询咨询附件")
    public ResultData<PageResult<ArticleAttachmentParam>> findByPage(@RequestBody QueryPageBean queryPageBean){
        log.info("【==========系统正在分页查询咨询信息，前端分页查询数据为{}：=============】",queryPageBean);
        PageResult<ArticleAttachmentParam> pageResult = articleAttachmentService.findByPage(queryPageBean);
        log.info("【==========系统正在分页查询咨询信息成功！=============】");
        return ResultData.success(Const.QUERY_ARTICLE_ATTACHMENT_SUCCESS,pageResult);
    }




}

